/*
*  Copyright 2019-2025 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.transfer.service.impl;

import me.zhengjie.modules.transfer.domain.TransferIc60;
import me.zhengjie.utils.FileUtil;
import lombok.RequiredArgsConstructor;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import me.zhengjie.modules.transfer.service.TransferIc60Service;
import me.zhengjie.modules.transfer.domain.dto.TransferIc60QueryCriteria;
import me.zhengjie.modules.transfer.mapper.TransferIc60Mapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import me.zhengjie.utils.PageUtil;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import me.zhengjie.utils.PageResult;

/**
* @description 服务实现
* @author lzw
* @date 2025-05-29
**/
@Service
@RequiredArgsConstructor
public class TransferIc60ServiceImpl extends ServiceImpl<TransferIc60Mapper, TransferIc60> implements TransferIc60Service {

    private final TransferIc60Mapper transferIc60Mapper;

    @Override
    public PageResult<TransferIc60> queryAll(TransferIc60QueryCriteria criteria, Page<Object> page){
        return PageUtil.toPage(transferIc60Mapper.findAll(criteria, page));
    }

    @Override
    public List<TransferIc60> queryAll(TransferIc60QueryCriteria criteria){
        return transferIc60Mapper.findAll(criteria);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(TransferIc60 resources) {
        transferIc60Mapper.insert(resources);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(TransferIc60 resources) {
        TransferIc60 transferIc60 = getById(resources.getAaz341());
        transferIc60.copy(resources);
        transferIc60Mapper.updateById(transferIc60);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteAll(List<String> ids) {
        transferIc60Mapper.deleteBatchIds(ids);
    }

    @Override
    public void download(List<TransferIc60> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (TransferIc60 transferIc60 : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("人员参保关系ID", transferIc60.getAaz159());
            map.put("转出地行政区划代码", transferIc60.getAab301());
            map.put("转入地行政区划代码", transferIc60.getAab299());
            map.put("联系函编号", transferIc60.getAae270());
            map.put("信息表编号", transferIc60.getAae405());
            map.put("转出险种类型", transferIc60.getAae140());
            map.put("转入险种类型", transferIc60.getAae241());
            map.put("人员编号", transferIc60.getAac001());
            map.put("姓名", transferIc60.getAac003());
            map.put("性别", transferIc60.getAac004());
            map.put("公民身份号码", transferIc60.getAac002());
            map.put("出生日期", transferIc60.getAac006());
            map.put("户籍地址", transferIc60.getAac010());
            map.put("转出单位名称", transferIc60.getAab300());
            map.put("职业年金总额", transferIc60.getAie074());
            map.put("记账金额", transferIc60.getAae240());
            map.put("实账金额", transferIc60.getAae252());
            map.put("补记的职业年金金额", transferIc60.getAic290());
            map.put("改革前试点划转金额", transferIc60.getAic005());
            map.put("企业年金金额", transferIc60.getAae019());
            map.put("转出方经办人电话", transferIc60.getAae005());
            map.put("转移数据来源", transferIc60.getAac306());
            map.put("联网下载标志", transferIc60.getAae732());
            map.put("被确认标志", transferIc60.getAae733());
            map.put("上传标志", transferIc60.getAae730());
            map.put("上传方经办人", transferIc60.getAae736());
            map.put("上传方经办时间", transferIc60.getAae739());
            map.put("备注", transferIc60.getAae013());
            map.put("经办人", transferIc60.getAae011());
            map.put("经办时间", transferIc60.getAae036());
            map.put("经办机构", transferIc60.getAab359());
            map.put("业务日志ID", transferIc60.getAaz002());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}
